hexStr = input()
num = 0
r = 0
for i in range(len(hexStr) - 1, -1, -1):
    c = hexStr[i]
    if '0' <= c <= '9':
        num += (ord(c) - ord('0')) * 16 ** r
    else:
        num += (ord(c) - ord('a') + 10) * 16 ** r
    r += 1
print(num)
